package com.fan.leetcode;

import java.util.Arrays;

/**
 * 611. 有效三角形的个数
 *
 * @author ZhangFan
 * @since 2021/8/4 下午 9:42
 */
public class Question611 {
    public int triangleNumber(int[] nums) {
        Arrays.sort(nums);
        int count = 0;
        for (int i = 0; i < nums.length; i++) {
            for (int j = i + 1; j < nums.length; j++) {
                for (int k = j + 1; k < nums.length; k++) {
                    if (nums[i] + nums[j] > nums[k] && nums[i] + nums[k] > nums[j] && nums[j] + nums[k] > nums[i]) {
                        count++;
                    } else {
                        break;
                    }
                }
            }
        }
        return count;
    }
}
